<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Student {
            constructor(name) {
                this.name = name;
            }
            hello() {
                alert("Hello, " + this.name + "!");
            }
        }

        var zhangsan = new Student("张三");
        console.log(zhangsan.hello());

        class PrimaryStudent extends Student {
            constructor(name,grade) {
                super(name);
                this.grade = grade;
            }
            myGrade() {
                alert('I am at grade' + this.grade);
            }
        }

        // 练习
        class Animal {
            constructor(name) {
                this.name = name;
            }
        }

        class Cat extends Animal{
            say() {
                return `Hello, ${this.name}!`;
            }
        }

        // 测试:
        var kitty = new Cat('Kitty');
        var doraemon = new Cat('哆啦A梦');
        if ((new Cat('x') instanceof Animal)
            && kitty 
            && kitty.name === 'Kitty'
            && kitty.say
            && typeof kitty.say === 'function'
            && kitty.say() === 'Hello, Kitty!'
            && kitty.say === doraemon.say)
        {
            console.log('测试通过!');
        } else {
            console.log('测试失败!');
        }
    </script>
</body>
</html>